package com.feng.utils;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

public class PathUtils {

    public static String imgPath(String path,String fileName){
        SimpleDateFormat format =  new SimpleDateFormat("yyyy/MM/dd");
        String datePath = format.format(new Date());

        String uuid = UUID.randomUUID().toString().replace("-", "");

        int index = fileName.lastIndexOf(".");
        String fileType = fileName.substring(index);
        File file = new File(path);
        if(!file.exists()){
            file.mkdirs();
        }
        String[] split = datePath.split("/");
        for(String s : split){
            file = new File(file.getPath() + "/" + s);
            if(!file.exists()){
                file.mkdirs();
            }
        }
        return new StringBuilder().append(datePath).append("/").append(uuid).append(fileType).toString();
    }
}
